//
//  VKStudyLeaveCell.m
//  V-Learn
//
//  Created by liubo on 2019/2/12.
//  Copyright © 2019 yxk. All rights reserved.
//

#import "VKStudyLeaveCell.h"

@implementation VKStudyLeaveCell{
    UILabel *_titleLabel;
    UIImageView *_arrowImageV;
}

+ (instancetype)cellWithTableView:(UITableView *)tableView withModel:(VKStudyLeaveModel *)model withIndexPath:(NSIndexPath *)indexPath{
    VKStudyLeaveCell *cell = [tableView dequeueReusableCellWithIdentifier:@"VKStudyLeaveCell"];
    if (cell == nil) {
        cell = [[VKStudyLeaveCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"VKStudyLeaveCell"];
        if (indexPath.section == 1) {
            if (indexPath.row == 2) {
                UITextField *contentTextField = [[UITextField alloc]init];
                contentTextField.tag = 8888;
                contentTextField.placeholder = @"请输入时长";
                contentTextField.textAlignment = NSTextAlignmentRight;
                
                [cell.contentView addSubview:contentTextField];
                contentTextField.textColor = [UIColor cz_colorWithRed:107 green:107 blue:107];
                contentTextField.font = [UIFont systemFontOfSize:16];
                contentTextField.keyboardType = UIKeyboardTypeNumberPad;//键盘类型
                [contentTextField mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.right.mas_equalTo(-25);
                    make.centerY.mas_equalTo(cell.contentView);
                    make.width.equalTo(@83.8);
                }];
            }
        }else if (indexPath.section == 2){
            UILabel *titleLabel = [[UILabel alloc]init];
            [cell.contentView addSubview:titleLabel];
            titleLabel.text = model.leftLabel;
            titleLabel.textColor = [UIColor cz_colorWithRed:62 green:62 blue:62];
            titleLabel.font = [UIFont systemFontOfSize:16];
            [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(15);
                make.top.mas_equalTo(20);
            }];
            
            UITextView *textView = [[UITextView alloc]init];
            textView.tag = 6666;
            //    self.textView.layer.cornerRadius = 5;
            //    self.textView.layer.masksToBounds = YES;
            textView.placeholder = @"请输入请假事由";
            textView.placeholderColor = [UIColor cz_colorWithHex:0xFFB2B3B7];
            [cell.contentView addSubview:textView];
            textView.font = [UIFont systemFontOfSize:16];
            textView.delegate = self;
            textView.backgroundColor = [UIColor whiteColor];
            [textView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(@12);
                make.right.equalTo(@(-15));
                make.top.mas_equalTo(titleLabel).offset(20);
                make.bottom.mas_equalTo(cell.contentView).offset(-10);
            }];
        }
    }
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    return cell;
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // 点击cell的时候不要变色
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor whiteColor];
        
        // 布局子控件
        [self autoLayout];
    }
    return self;
}

-(void)setModel:(VKStudyLeaveModel *)model{
    _titleLabel.text = model.leftLabel;
    [_contentBtn setTitle:[NSString stringWithFormat:@"  %@",model.rightLabel] forState:UIControlStateNormal];
//    _contentLabel.text = model.rightLabel;
    NSIndexPath *indexPath = model.indexPath;
    if (indexPath.section == 1) {
        if (indexPath.row == 2) {
            _arrowImageV.hidden = YES;
            _contentBtn.hidden = YES;
        }
    }else if (indexPath.section == 2){
        if (indexPath.row == 0) {
            _arrowImageV.hidden = YES;
            _contentBtn.hidden = YES;
            _titleLabel.hidden = YES;
        }
    }
}

- (void)autoLayout{
    
    UILabel *titleLabel = [[UILabel alloc]init];
    _titleLabel = titleLabel;
    [self.contentView addSubview:titleLabel];
    //    titleLabel.text = @"小苹果";
    titleLabel.textColor = [UIColor cz_colorWithRed:62 green:62 blue:62];
    titleLabel.font = [UIFont systemFontOfSize:16];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.centerY.mas_equalTo(self.contentView);
    }];
    
    UIImageView *arrowImageV = [[UIImageView alloc]init];
    _arrowImageV = arrowImageV;
    arrowImageV.image = [UIImage imageNamed:@"left"];
    [self.contentView addSubview:arrowImageV];
    [arrowImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.right.mas_equalTo(-15);
    }];
    
    
    UIButton *contentBtn = [[UIButton alloc]init];
    [self.contentView addSubview:contentBtn];
    _contentBtn = contentBtn;
    //    contentLabel.text = @"小苹果";
    contentBtn.backgroundColor = [UIColor whiteColor];
//    contentBtn.titleLabel.textAlignment = NSTextAlignmentRight;
    contentBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    contentBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
    [contentBtn setTitleColor:[UIColor cz_colorWithRed:107 green:107 blue:107] forState:UIControlStateNormal];
    contentBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [contentBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(arrowImageV.mas_left).offset(-10);
        make.centerY.mas_equalTo(self.contentView);
        make.width.mas_equalTo(180*kScaleFit);
        make.height.equalTo(@30);

    }];
    
    UIView *lineView = [[UIView alloc]init];
    [self.contentView addSubview:lineView];
    lineView.backgroundColor = [UIColor cz_colorWithRed:244 green:244 blue:244];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(@0);
        make.height.equalTo(@1);
        make.bottom.mas_equalTo(self.contentView);
    }];
    
}

@end
